n = int(input())
a = list(map(str, input().split()))
for j in range(n):
    for k in range(n-j-1):
        if (a[k][-1] > a[k+1][-1]) or (a[k][-1] == a[k+1][-1] and int(a[k]) > int(a[k+1])):
            a[k], a[k+1] = a[k+1], a[k]
for i in range(n - 1):
    print((a[i]), end=' ')
print((a[-1]))
